package com.testing.runner;

import com.testing.app.AppKeyword;
import com.testing.common.AutoTools;
import com.testing.common.ExcelReader;
import com.testing.common.ExcelWriter;
import com.testing.common.Report;
import com.testing.inter.InterKeyword;
import com.testing.web.WebKeyword;

import java.lang.reflect.Method;
import java.util.List;

/**
 * @Classname AutoFrame
 * @Description 类型说明
 * @Date 2021/6/30 22:36
 * @Created by 特斯汀Roy
 */
public class AutoFrame {

    private static String casefile="Cases/";
    private static String resultfile="Cases/Result/";
    private static Object keyWord;
    private static ExcelReader cases;
    private static ExcelWriter results;

    public static void main(String[] args) throws Exception {
        //将3个自动化类别整合到一起。
        String type=args[0];
        String caseName=args[1];
        String time= AutoTools.timeStampString("MMdd-HHmmss");
        String startTime= AutoTools.timeStampString("yyyy-MM-dd HH:mm:ss");
        switch (type){
            case "web":
                casefile+=caseName;
                resultfile+="WebResult"+ time;
                cases=new ExcelReader(casefile);
                results=new ExcelWriter(casefile,resultfile);
                keyWord=new WebKeyword(results);
                break;
            case "app":
                casefile+=caseName;
                resultfile+="APPResult"+ time;
                cases=new ExcelReader(casefile);
                results=new ExcelWriter(casefile,resultfile);
                keyWord=new AppKeyword(results);
                break;
            case "inter":
                casefile+=caseName;
                resultfile+="InterResult"+ time;
                cases=new ExcelReader(casefile);
                results=new ExcelWriter(casefile,resultfile);
                keyWord=new InterKeyword(results);
                break;
        }
        //遍历每一行用例
        for(int sheetNo=0;sheetNo<cases.getTotalSheetNo();sheetNo++){
            //指定使用当前的sheet页
            cases.useSheetByIndex(sheetNo);
            results.useSheetByIndex(sheetNo);
            for(int rowNo=0;rowNo<cases.getRowNo();rowNo++){
                //设置关键字对象，当前要写入哪一行
                Method setWriteLine = keyWord.getClass().getMethod("setWriteLine",int.class);
                setWriteLine.invoke(keyWord,rowNo);
                //执行用例，完成发包
                List<String> rowContent = cases.readLine(rowNo);
                //执行用例
                AutoTools.invokeKeyWord(keyWord,rowContent,3);
                if (rowContent.get(7).trim().length()>2)
                //执行断言
                AutoTools.invokeKeyWord(keyWord,rowContent,7);
            }
        }
        cases.close();
        results.save();
        Report.sendreport(resultfile,startTime);

    }


}
